import { ColumnConfig } from "./ColumnConfig"
export class ColumnButton {
  constructor(h, text, icon) {
    this._vue = ColumnConfig.Vue;
    this.events = {};
    this.attr = {
      tag: "operate-button",
      primaryKey: "id",
      data: {}
    };
    this.properties = {
      h,
      text,
      icon,
      props: {}
    }
  }

  props(value) { this.properties.props = value; return this; }

  tag(value) { this.attr.tag = value; return this; }

  text(value) { this.properties.text = value; return this; }

  icon(value) { this.properties.icon = value; return this; }

  click(value) { this.events.click = value; return this; }

  dataKey(value) { this.properties.dataKey = value; return this; }

  data(value) { this.attr.data = value; return this; }

  primaryKey(value) { this.attr.primaryKey = value; return this; }

  getPrimaryValue() { return this.attr.data[this.attr.primaryKey]; }

  build() {
    const h = this.properties.h;
    const icon = this.properties.icon;
    const text = this.properties.text;
    const props = {
      ...this.properties.props,
      icon,
      text
    };
    const on = { ...this.events };
    return h(this.attr.tag, { props, on });
  }
}
